From 70efcfeaa0603415dd992cb662d8efb960e6e49a Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Tue, 26 Sep 2023 15:54:28 +0200 Subject: refactor(routes): replace hardcoded routes with constants It makes it easier to change a route if needed and it avoid typo mistakes. I also refactored a bit the concerned files to be complient with the new ESlint config. However, I should rewrite the pages to reduce the number of statements. --- src/pages/sujet/[slug].tsx | 63 ++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 30 deletions(-) (limited to 'src/pages/sujet/[slug].tsx') diff --git a/src/pages/sujet/[slug].tsx b/src/pages/sujet/[slug].tsx index 6308978..94541b9 100644 --- a/src/pages/sujet/[slug].tsx +++ b/src/pages/sujet/[slug].tsx @@ -1,17 +1,18 @@ -import { GetStaticPaths, GetStaticProps } from 'next'; +/* eslint-disable max-statements */ +import type { ParsedUrlQuery } from 'querystring'; +import type { GetStaticPaths, GetStaticProps } from 'next'; import Head from 'next/head'; import { useRouter } from 'next/router'; import Script from 'next/script'; -import { ParsedUrlQuery } from 'querystring'; import { useIntl } from 'react-intl'; import { getLayout, Heading, LinksListWidget, PageLayout, - type PageLayoutProps, PostsList, ResponsiveImage, + type MetaData, } from '../../components'; import { getAllTopicsSlugs, @@ -20,11 +21,8 @@ import { getTotalTopics, } from '../../services/graphql'; import styles from '../../styles/pages/topic.module.scss'; -import { - type NextPageWithLayout, - type PageLink, - type Topic, -} from '../../types'; +import type { NextPageWithLayout, PageLink, Topic } from '../../types'; +import { ROUTES } from '../../utils/constants'; import { getLinksListItems, getPageLinkFromRawData, @@ -58,10 +56,10 @@ const TopicPage: NextPageWithLayout = ({ const intl = useIntl(); const { items: breadcrumbItems, schema: breadcrumbSchema } = useBreadcrumb({ title, - url: `/sujet/${slug}`, + url: `${ROUTES.TOPICS}/${slug}`, }); - const headerMeta: PageLayoutProps['headerMeta'] = { + const headerMeta: MetaData = { publication: { date: dates.publication }, update: dates.update ? { date: dates.update } : undefined, website: officialWebsite, @@ -101,28 +99,32 @@ const TopicPage: NextPageWithLayout = ({ id: '/sRqPT', }); - const getPageHeading = () => { - return ( - <> - {cover && } - {title} - - ); - }; + const getPageHeading = () => ( + <> + {cover ? : null} + {title} + + ); + const pageUrl = `${website.url}${asPath}`; + const postsListBaseUrl = `${ROUTES.TOPICS}/page/`; return ( <> {seo.title} + {/*eslint-disable-next-line react/jsx-no-literals -- Name allowed */} - + + {/*eslint-disable-next-line react/jsx-no-literals -- Content allowed */}